/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package issr.controller;

import issr.entity.Ruolo;
import issr.entity.Utente;
import issr.persistence.Database;
import java.util.ArrayList;
import java.util.Date;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;

/**
 *
 * @author Soulreaver
 */
@WebService(serviceName = "ControlloreCreazioneDipendenteAmministratoreG")
@Stateless()
public class ControlloreCreazioneDipendenteAmministratoreG {

    private Database db = Database.getInstance();

    /**
     * Web service operation
     */
    @WebMethod(operationName = "creaNuovoDipendente")
    public boolean creaNuovoDipendente(@WebParam(name = "nome") String nome, @WebParam(name = "cognome") String cognome, @WebParam(name = "login") String login, @WebParam(name = "password") String password, @WebParam(name = "email") String email, @WebParam(name = "cellulare") String cellulare, @WebParam(name = "ruolo") Ruolo ruolo, @WebParam(name = "corrente") Utente corrente) {
        if (password.matches("^[a-zA-Z0-9]+$")) {
            try {
                Utente user = new Utente(ruolo, login, password, nome, cognome, email, cellulare, new Date());
                db.creaNuovoDipendente(user);
                db.aggiungiEntry(
                        corrente,
                        "Utente creato: " + login + " (" + ruolo.getNome() + ")");
                return true;
            } catch (Exception e) {
                return false;
            }
        } else {
            return false;
        }
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "getListaRuoli")
    public ArrayList<Ruolo> getListaRuoli() {
        return db.caricaRuoli();
    }
}
